<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>201.品牌列表案例</title>
    <script src="./lib/vue-2.6.12.js"></script>
    <script src="./lib/axios.min.js"></script>
    <link rel="stylesheet" href="./lib/bootstrap-3.3.7.css">
</head>

<body>
    <div id="app">

        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">添加品牌</h3>
            </div>
            <div class="panel-body form-inline">
                <label>Id: <input type="text" class="form-control" v-model="id"></label>
                <label>Name: <input type="text" class="form-control" v-model="name"></label>
                <button type="button" class="btn btn-primary" @click="add">添加</button>
            </div>
        </div>

        <table class="table table-hover table-bordered table-striped">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>名称</th>
                    <th>时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in list" :key="item.id">
                    <td>{{ item.id}}</td>
                    <td v-text="item.name"></td>
                    <td>{{item.ctime}}</td>
                    <td> <a href="" @click.prevent="del(item.id)">删除</a></td>
                </tr>
            </tbody>
        </table>

    </div>

    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                id: '',
                name: '',
                keyword: '',
                list: [
                    { id: 1, name: '奔驰', ctime: new Date() },
                    { id: 2, name: '宝马', ctime: new Date() }
                ]
            },
            methods: {
                add() {
                    let car = { id: this.id, name: this.name, ctime: new Date() };
                    this.list.push(car);
                    this.id = this.name = '';
                },
                del(id) {
                    let idx = this.list.findIndex(item => {
                        if (item.id == id) {
                            return true;
                        }
                    })
                    this.list.splice(idx, 1);
                },
                getAllList() {
                    
                }
            }
        })        
    </script>
</body>

</html>